//##include('../block/lazyload.js');
//##include('../block/swiper.js');
//##include('../block/direction.js');

var $doc,
    $pswpCloseBtn,
    $pswpCaption,
    $pswpCaptionCenter,
    startX,
    startY,
    X,
    Y,
    READ_FLAG = {};

var _view = {

    init: function() {
        //$pswpCloseBtn.click();
        this.setReadStatus();
        _view.initSlideSwipe();
        this.lazyimg();
    },

    initSlideSwipe : function(){
        var wiperAtlas = new Swiper('#swiper-container-atlas',{
            pagination : '#swiper-pagination-atlas',
            paginationType: 'fraction'
        });
    },
    lazyimg:function(){
        $(".lazy").lazyload({
            effect : "fadeIn"
        });
    },

    setReadStatus : function(){
        var urls = window.location.href;
        var url_params = urls.substring(parseInt(urls.lastIndexOf('/')+1));


        var readT = 'T10';
        var readID = url_params.split('_')[1];
        var localReadD;

        //如果localStorage没有READ_D
        if (!localStorage.getItem('READ_D')) {
            READ_FLAG[readT] = [];
            READ_FLAG[readT].push(readID);

            //存取最开始点击的数据到localStorage
            localStorage.setItem('READ_D', JSON.stringify(READ_FLAG));
        }else{

            //获取最新localStorage的READ_D信息
            localReadD = JSON.parse(localStorage.getItem('READ_D'));

            //获取对应的type数组
            var readTypeArr = localReadD[readT];

            //如果有当前点击的type数组
            if(readTypeArr){

                //判断当前点击的id是否在数组中
                var inRead = $.inArray(readID,readTypeArr);

                //如果没有
                if(inRead == -1){

                    //限定存取的最大条数,超出删除第一条
                    if(readTypeArr.length >= 30){
                        readTypeArr.shift();
                    }
                    readTypeArr.push(readID);
                    //console.log(readTypeArr);
                    //更新localStorage
                    localStorage.setItem('READ_D', JSON.stringify(localReadD));
                }

                //如果没有当前点击对应的数组
            }else{
                //取得最新localStorage并创建对应的数组
                localReadD = JSON.parse(localStorage.getItem('READ_D'));
                localReadD[readT] = [];
                localReadD[readT].push(readID);
                //更新localStorage
                localStorage.setItem('READ_D', JSON.stringify(localReadD));
            }
        }
    }

};

var _event = {

    bind: function() {}
};

var _data = {};

function init() {
    _view.init();
    _event.bind();
}

$(document).ready(function(){

    $doc = $(document);
    $pswpCloseBtn = $('.pswp__button--close');
    $pswpCaption = $('.pswp__caption');
    $pswpCaptionCenter = $('.pswp__caption__center');




    init();

    //$(window).on('resize', function() {
    //    document.documentElement.style.fontSize = document.documentElement.getBoundingClientRect().width/3.75 + 'px';
    //})



});
